<%@page import="cn.com.dhcc.app.core.PluginPara"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>${appname}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<%@ include file="/WEB-INF/view/common/css_js_ztree.jsp"%>
<script type="text/javascript">
	$(function() {
		$("#inputForm").checkForm(setRsAndChech);
	});
	
	var forSl = ${isSlUams};
	function setRsAndChech() {
		var checkedRights = $.getCheckBoxValueStr('rightIds');
		if(checkedRights==''){
			alert("请选择权限！");
			return false;
		}
		if(forSl){
			var orgs = $("#orgCodes").val();
			if(orgs==''){
				alert("请选择组织机构！");
				return false;
			}
		}
	}
	var safeRoleType = 4;
	var authRoleType = 8;
	function checkTypeSelected(checkbox){
		var rightType = $(checkbox).attr("rightType");
		var roleTypeSelected = $("#roleType").val();
		var toSelect = $(checkbox).is(':checked');
		var msg = "不能同时包含安全保密管理员和安全审计员！";
		if(toSelect){
			if(rightType==safeRoleType){
				if(roleTypeSelected==authRoleType){
					alert("角色类型和权限类型不否，安全审计员角色不能包含安全保密管理员权限");
					return false;
				}
				var authRoleTypeLength = $(":checkbox[name='rightIds'][rightType='"+authRoleType+"']:checked").size();
				if(authRoleTypeLength>0){
					alert(msg);
					return false;
				}
			}
			if(rightType==authRoleType){
				if(roleTypeSelected==safeRoleType){
					alert("角色类型和权限类型不否，安全保密管理员角色不能包含安全审计员权限");
					return false;
				}
				var safeRoleTypeLength = $(":checkbox[name='rightIds'][rightType='"+safeRoleType+"']:checked").size();
				if(safeRoleTypeLength>0){
					alert(msg);
					return false;
				}
			}
		}
		return true;
	}
	var roleTypeSelectedPreVal='';
	function checkTypeChange(selected){
		var roleType = $(selected).val();
		if(roleType==safeRoleType){
			var authRoleTypeLength = $(":checkbox[name='rightIds'][rightType='"+authRoleType+"']:checked").size();
			if(authRoleTypeLength>0){
				alert("角色类型和权限类型不否，安全保密管理员角色不能包含安全审计员权限！");
				$(selected).val(roleTypeSelectedPreVal);
				return false;
			}
		}
		if(roleType==authRoleType){
			var safeRoleTypeLength = $(":checkbox[name='rightIds'][rightType='"+safeRoleType+"']:checked").size();
			if(safeRoleTypeLength>0){
				alert("角色类型和权限类型不否，安全审计员角色不能包含安全保密管理员权限！");
				$(selected).val(roleTypeSelectedPreVal);
				return false;
			}
		}
		roleTypeSelectedPreVal = roletType;
	}
	
	$(document).ready(function() {
		$("#div1").css({
			"left" : $("#tab1").width() + 60,
			"position" : "absolute",
			"width" : "350px",
			"float" : "right"
		});
	});
	/**
	 * 通过弹出的单位树选择组织机构编码 
	 */
	function orgSelect() {
		$('#orgSelectModal').modal('show');
		var hasSelectedOrgCodes = $('#orgCodes').val();
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/pub/sysmgr/authmgr/org_select.do?hasSelectedOrgCodes="+hasSelectedOrgCodes,
			success : function(content) {
				$('#orgSelect').html(content);
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function getRightMenus(rightId){
		$('#menuidsModal').modal('show');
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/pub/sysmgr/authmgr/get_right_menu.do?rightId="+rightId,
			success : function(content) {
				$('#menuSelect').html(content);
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function selectedOrg(){
		$('#orgSelectModal').modal('hide');
	};
</script>
<style type="text/css">
div.zTreeDemoBackground {
	width: 350px;
	height: 340px;
	text-align: left;
}

ul.ztree {
	margin-top: 10px;
	width: 300px;
	height: 320px;
	overflow-y: scroll;
	overflow-x: auto;
}
</style>
</head>
<body>
	<%-- <%@ include file="/WEB-INF/view/common/topbar.jsp"%> --%>
	<div class="main-container" id="main-container">
		<div class="main-container-inner">
			<%-- <%@ include file="/WEB-INF/view/common/topbar.jsp"%> --%>
			<div class="main-content" style="margin-left: 0px;">
				<div class="breadcrumbs" id="breadcrumbs">
					<ul class="breadcrumb" style="margin-left: 4px;">
						<li><i class="icon-home home-icon"></i>首页</li>
						<li>通用模块</li>
						<li>角色管理</li>
						<li class="active">添加角色</li>
					</ul>
				</div>
				<div class="page-content">
					<form action="${ctx}/pub/sysmgr/authmgr/add_role.do" method="post" class="form-horizontal"
						id="inputForm">
						<input type="hidden" name="backurl" value="${backurl}" />
						 <input type="hidden" name="resources" value="" id="resources" />
						<div class="row">
							<div class="col-xs-4">
								<div class="widget-box" style="border-bottom:1px solid #FFFFFF;">
									<div id="operation_div">
										<div class="table-responsive"></div>
									</div>
									<div class="space-4"></div>
									<div class="form-group">
										<div class="col-sm-3 control-label no-padding-right"
											for="form-field-1">角色名称 *</div>
										<div class="col-sm-9">
											<input type="text" name="roleName" id="roleName"
												value="${param.roleName}" class="col-xs-10 col-sm-8" 
												maxlength="200" require="true" value=""
												datatype="require|limit|ajax" min="1" max="200"
												msg="请填写角色名称！|角色名称最多200个英文字符!|角色名称已经被占用！"
												url="${ctx}/pub/sysmgr/authmgr/check_role_name.do" oldValue=""
												title="必填项,1-200个字符，允许中文，英文字母、数字和符号" /> <label
												id="success_roleName" style="display:none;"><span
												class="ico_cue_ok"></span> </label> <label class="error_roleName"
												style="display:none;" for="roleName"><span
												class="ico_cue_no"></span> <span class="alert-error"
												id="error_roleName"></span> </label>
										</div>
									</div>
									<div class="space-4"></div>
									<div class="form-group">
										<div class="col-sm-3 control-label no-padding-right"
											for="form-field-1">角色类型*</div>
										<div class="col-sm-9">
											<select name="roleType" id="roleType"  onchange="checkTypeChange(this)"
											   require="true" datatype="require" msg="请选择角色类型！"
												class="col-xs-10 col-sm-8" >
												<option value="">-请选择-</option>
												${cm:ctoption('authusertype','')}
											</select>
										</div>
									</div>
									<c:if test="${isSlUams eq true}">
										<div class="space-4"></div>
										<div class="form-group">
											<div class="col-sm-3 control-label no-padding-right"
												for="form-field-1">所属组织*</div>
											<div class="col-sm-9">
											<input type="hidden" name="orgCodes" id="orgCodes" value=""/>
											<input type="hidden" name="orgNames" id="orgNames" value=""/>
											<a class="btn btn-primary btn-xs"  onclick="javascript:orgSelect()">选择组织机构&nbsp;&nbsp;</a>
											<div id="hasSelectedOrgNums"></div>
											</div>
										</div>
									</c:if>
									<div class="space-4"></div>
									<div class="form-group">
										<div class="col-sm-3 control-label no-padding-right"
											for="form-field-1">描述：</div>
										<div class="col-sm-9">
											<textarea class="col-xs-15 col-sm-8"  name="remark"></textarea>
										</div>
									</div>
									<div class="clearfix form-group">
										<div class="col-md-offset-3 col-md-3">
											<button type="submit" class="btn btn-sm btn-success" id="sbmBtn"><i class="icon-ok bigger-110"></i>提交</button>
										</div>
										<div>
											<button type="button" class="btn btn-sm btn-info" id="returnBtn" onclick="javascript:history.go(-1);"><i class="icon-arrow-left bigger-110"></i>返回</button>
								 		</div>
									</div>
								</div>
							</div>

							<div class="col-xs-8">
								<div class="widget-box">
									<div class="widget-header widget-header-flat">
										<h5 class="smaller lighter">选择权限</h5>
									</div>
									<div class="widget-body">
										<div class="widget-main">
											<div class="row mg-top12"
												style="overflow:auto; height: 400px; border-top:1px solid #CCCCCC;">
										<table id="sample-table-1"
										class="table table-striped table-bordered table-hover">
										<thead>
											<tr>
											    <th>
											      <label>
												    <span class="lbl"></span>
												   </label>
                                                </th>
												<th>权限名称</th>
												<th>权限类型</th>
												<th>状态</th>
												<th>创建时间</th>
												<th>描述</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											<c:forEach var="r" items="${rights}">
												<tr>
												    <td>
												     <label>
												      		<input type="checkbox" class="ace" name="rightIds" rightType="${r.type}" value="${r.id}" onclick="return checkTypeSelected(this);"/>
												      		<span class="lbl"></span>
												      </label>
												    </td>
													<td>${r.rightName}&nbsp;</td>
													<td>${cm:ctname('authusertype',r.type)}&nbsp;</td>
													<td>${cm:ctname('entity_status',r.status)}&nbsp;</td>
													<td><fmt:formatDate value="${r.modified}" pattern="yyyy-MM-dd HH:mm:ss" />&nbsp;</td>
													<td>${r.remark}&nbsp;</td>
													<td align="center" >
													<a class="blue" href="javascript:void(0);" onclick="javascript:getRightMenus('${r.id}');" title="查看权限资源">
														 	<i class="icon-zoom-in bigger-130"></i>  
													 </a>
													</td>
												</tr>
											</c:forEach>
										</tbody>
									</table>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
				</div>
			</div>
			<div id="orgSelectModal" class="modal fade" role="dialog" tabindex="-1" aria-labelledby="查看" aria-hidden="false">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class='widget-header widget-header-small'><h5 class='smaller'> 组织机构</h5></div>
						<div id="orgSelect">
							<p class="text-center" style="font-size: 25px; color: #428bca;">
								<span class="icon icon-cog icon-spin"></span>
							</p>
							<p class="text-center" style="font-size: 12px; color: #428bca; margin-top: -10px; margin-bottom: 0px;">
								<span>组织机构信息加载中...</span>
							</p>
						</div>
					</div>
				</div>
			</div>
			<div id="menuidsModal" class="modal fade" role="dialog" tabindex="-1" aria-labelledby="查看" aria-hidden="false">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class='widget-header widget-header-small'><h5 class='smaller'> 权限资源</h5></div>
						<div id="menuSelect">
							<p class="text-center" style="font-size: 25px; color: #428bca;">
								<span class="icon icon-cog icon-spin"></span>
							</p>
							<p class="text-center" style="font-size: 12px; color: #428bca; margin-top: -10px; margin-bottom: 0px;">
								<span>资源信息加载中...</span>
							</p>
						</div>
					</div>
				</div>
			</div>
			</form>
		</div>
	</div>
</body>
</html>
